var province = 
[
["0","--\u8bf7\u9009\u62e9--"],
["410100","\u90d1\u5dde"],
["410200","\u5f00\u5c01"],
["410300","\u6d1b\u9633"],
["410400","\u5e73\u9876\u5c71"],
["410500","\u5b89\u9633"],
["410600","\u9e64\u58c1"],
["410700","\u65b0\u4e61"],
["410800","\u7126\u4f5c"],
["410900","\u6fee\u9633"],
["411000","\u8bb8\u660c"],
["411100","\u6f2f\u6cb3"],
["411200","\u4e09\u95e8\u5ce1"],
["411300","\u5357\u9633"],
["411400","\u5546\u4e18"],
["411500","\u4fe1\u9633"],
["411600","\u5468\u53e3"],
["411700","\u9a7b\u9a6c\u5e97"],
["411800","\u6d4e\u6e90"]
];
(function($){
	 $.fn.SchoolLiList = function(options){
		var defaults = {
			url:"",
			spellAction    : "",
			areaCodeAction : "",
			hidSclid:"",
			afterClick:function(li_schname,li_sclid){}
		};
		var options = $.extend(defaults, options);
		var _obj =$("#schoolName");
		_obj.focus(function(){
			_obj[0].select();
		    var top = $(this).position().top;
    	    var left = $(this).position().left-70;
    	    $("div.provinceSchool").css({top:top,left:left});
    	    $("div.provinceSchool").show();
    	    console.log(left);
		});
		
		var provinceArray = "";
		var provicneSelectStr = "";
		for(var i=0,len=province.length;i<len;i++){
		  provinceArray = province[i];
		  provicneSelectStr = provicneSelectStr + "<option value='"+provinceArray[0]+"'>"+provinceArray[1]+"</option>"
		} 
		$("div.proSelect select").html(provicneSelectStr);
		var selectPro = $("div.proSelect select").val();

		if(selectPro!=0){
		    var url=options.areaCodeAction;
		    var data={"areaCode":selectPro};
		    $.post(url,data,function(json){
		    	eachs(json);
		    },"json");
		}
		$("div.proSelect select").change(function(){
			    var sel_val=$(this).val();
			    if(sel_val==0){
			    	$("div.schoolList ul").html("");
			    	return;
			    }
			  	schoolUlStr = "";
			    var url=options.areaCodeAction;
			    var data={"areaCode":sel_val};
			    $.post(url,data,function(json){
					    eachs(json);
			    },"json");
		});
		_obj.keyup(function(event){
			   var vhidSclid=options.hidSclid;
    	       $("#"+vhidSclid).val("");
			   var keyCode = event.which;
			   var keyword=_obj.val();
			   keyword=$.trim(keyword);
			   if(keyword==""){
				   return;
			   }
			   $.post(options.spellAction,{"keyword":keyword},function(json){
				   eachs(json);
			   },'json');
		});
		function eachs(schoolListArray){
			var schoolUlStr="";
		    for(var i=0,len=schoolListArray.length;i<len;i++){
			      var ischool=schoolListArray[i];
			      var schName = ischool.value;
			      if(schName.length>10){
			    	  schoolUlStr = schoolUlStr + "<li schid='"+ischool.id+"' schname='"+schName+"' class='DoubleWidthLi'>"+schName+"</li>";
			      }else{
			    	  schoolUlStr = schoolUlStr + "<li schid='"+ischool.id+"' schname='"+schName+"'>"+schName+"</li>";
			      }
			  	  
			}
		    $("div.schoolList ul").html(schoolUlStr);
			$("div.schoolList ul li").bind("click",function(){
				afterLoad($(this));
			});			    
		}
		$("div.schoolList ul li").bind("mouseover",function(){
		  $(this).css("background-color","#72B9D7");
		});
		$("div.schoolList ul li").bind("mouseout",function(){
		  $(this).css("background-color","");
		});
		function afterLoad(cur_li){
			  var schname=cur_li.attr("schname");
			  var schid=cur_li.attr("schid");
			 
			  $("#schoolName").val(schname);
			  var vhidSclid=options.hidSclid;
			  if(vhidSclid!=""){
				  $("#"+vhidSclid).val(schid);
			  }
	  	      options.afterClick(schname,schid);
			  $("div.provinceSchool").hide();			
		}
		
		
		$("input[name='closebtn']").bind("click",function(){
			  	$("div.provinceSchool").hide();
		});
		
		$("#clearschool").bind("click",function(){
			 $("#schoolName").val("");
			  var vhidSclid=options.hidSclid;
			  if(vhidSclid!=""){
				  $("#"+vhidSclid).val("");
			  }
			 $("div.schoolList ul").html("");		 
			 $("#schoolName")[0].focus();
		});
		
		$("#reloadSchool").bind("click",function(){
		    var sel_val=$("#schAreaCode").val();
		    if(sel_val==0){
		    	$("div.schoolList ul").html("");
		    	return;
		    }
		  	schoolUlStr = "";
		    var url=options.areaCodeAction;
		    var data={"areaCode":sel_val};
		    $.post(url,data,function(json){
				    eachs(json);
		    },"json");
		});

	  }
   }
)(jQuery);